<!DOCTYPE html>
<html lang="en">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
      name="viewport">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
    <meta charset="UTF-8">
    <title>视频转换</title>
    <script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
    <script src="/dist/plugins/vue/vue.js"></script>
</head>
<body>
<div id="app">
    <h2>请复制视频的地址栏链接: [ 腾讯 | 优酷 ]</h2>
    <input type="text" style="width: 800px;height: 40px" v-model="nowUrl">
    <div style="margin-top: 20px"><a @click="find(nowUrl)"
                                     style="background:#2c8cec;cursor:pointer;color: #ffffff;padding: 5px;">一键转换原始地址</a>
    </div>

    <h2>{{resultText}}</h2>
    <input type="text" style="width: 800px;height: 40px" v-model="oriUrl"> <span
        id="downLoad" style="cursor:pointer;display: none"><u @click="downYKVideo">点此下载</u></span>

    <div>{{videoTitle}}</div>

</div>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            nowUrl: "https://v.qq.com/x/page/k0560xz8jcu.html",
            oriUrl: "",
            downUrl: "",
            videoTitle: "",
            resultText: "转换结果:",
        },
        methods: {
            find: function (nowUrl) {
                //复位
                $('#downLoad').css('display','none');
                this.downUrl = ''


                //腾讯视频
                if (nowUrl.indexOf('v.qq.com') > 0) {
                    this.findTXVideo(nowUrl)
                } else
                //优酷视频
                if (nowUrl.indexOf('v.youku.com') > 0) {
                    this.findYKVideo(nowUrl)
                } else {
                    this.resultText = "暂不支持..."
                    this.oriUrl = ""
                    this.videoTitle = ""
                }
            },
            findTXVideo(nowUrl) {
                this.resultText = "转换中..."
                //https://v.qq.com/x/page/k0560xz8jcu.html
                var fileName = nowUrl.substring(nowUrl.lastIndexOf("/") + 1);
                var vid = fileName.split(".")[0]
                console.log(vid)
                //http://vv.video.qq.com/getinfo?vids=x1320y27wx6&platform=101001&charge=0&otype=json&defn=sd
                var that = this
                $.ajax({
                    url: "http://vv.video.qq.com/getinfo?vids=" + vid + "&platform=101001&charge=0&otype=json&defn=sd",
                    contentType: 'application/json;charset=utf-8',
                    xhrFields: {
                        withCredentials: true // 设置运行跨域操作
                    },
                    type: "GET",
                    dataType: 'JSONP',
                    data: "",
                    success: function (r) {
                        console.log(r)
                        try {
                            if (r.vl.vi) {
                                that.resultText = "转换结果: 成功!"
                                var fn = r.vl.vi[0].fn
                                var fvkey = r.vl.vi[0].fvkey
                                that.videoTitle = r.vl.vi[0].ti
                                var url = r.vl.vi[0].ul.ui[0].url
                                that.oriUrl = url + fn + '?vkey=' + fvkey
                            }
                        } catch (e) {
                            that.resultText = "转换结果: 失败!"
                            that.oriUrl = ""
                            that.videoTitle = ""
                        }
                    },
                    error: function (e) {
                        console.log(e)
                        alert(e.responseText)
                    }
                });
            },
            findYKVideo(nowUrl) {
                var that = this
                this.resultText = "转换中..."
                //http://v.youku.com/v_show/id_XMTQ5OTEyOTU2NA==.html?spm=a2hzp.8244740.0.0
                //http://player.youku.com/player.php/sid/XMTQ5OTEyOTU2NA==/v.swf
                var vid = nowUrl.substring(nowUrl.indexOf("id_") + 3, nowUrl.indexOf("==.html"));
                //http://player.youku.com/embed/XMzkyNzg2NTEwNA
                that.resultText = "转换结果: 成功!"
                that.videoTitle = ''
                that.oriUrl = 'http://player.youku.com/embed/' + vid
                that.downUrl = 'http://player.youku.com/player.php/sid/'+vid+'==/v.swf'
                // $('#downLoad').css('display','');
            },
            downYKVideo(){
                window.open(this.downUrl);
            }
        },
    })
</script>
</body>
</html>